package com.example.print;

import android.app.Application;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;

import com.example.print.other.ScreenReceiver;

/**
 * Created by wskyo on 2022/8/10.
 */

public class App extends Application {

    private final static String TAG = "Serial.Init";
    //private static Context sContext;
    //private static App mApp;

    //private SerialPort mSerialPort = null;
    public String path;
    public int baudrate;

    public static boolean mInit = false;
    public static boolean mConnect = false;
    private ScreenReceiver sOnBroadcastReciver;

    @Override
    public void onCreate() {
        super.onCreate();

        Log.d(TAG, "-App.onCreate...");

//        SharedPreferences sp = this.getSharedPreferences("_serialport", Context.MODE_PRIVATE);
//        if (getPlatform().contains("mtk")) {
//            sp.edit().putString("DEVICE", "/dev/ttyS1").commit();
//        } else if(getPlatform().contains("sprd")){
//            sp.edit().putString("DEVICE", "/dev/ttyS2").commit();
//        }
//        //sp.edit().putString("DEVICE", "/dev/ttySWK0").commit(); //hejiang for high voltage print
//        sp.edit().putString("BAUDRATE", "115200").commit();//115200

        sOnBroadcastReciver = new ScreenReceiver();
        IntentFilter recevierFilter = new IntentFilter();
        //recevierFilter.addAction(Intent.ACTION_SCREEN_ON);
        recevierFilter.addAction(Intent.ACTION_SCREEN_OFF);
        recevierFilter.addAction(Intent.ACTION_USER_PRESENT);
        registerReceiver(sOnBroadcastReciver, recevierFilter);
    }

    @Override
    public void onTerminate() {
        // 程序终止的时候执行
        super.onTerminate();
        Log.d(TAG, "onTerminate");

        mInit = false;
        mConnect = false;
        //Print_Power_Off();
    }
    @Override
    public void onLowMemory() {
        // 低内存的时候执行
        super.onLowMemory();
        Log.d(TAG, "onLowMemory");
    }
    @Override
    public void onTrimMemory(int level) {
        // 程序在内存清理的时候执行
        super.onTrimMemory(level);
        Log.d(TAG, "onTrimMemory");
    }
}
